package Locomotive;

import java.awt.geom.Point2D;

/**
 *
 * @author Mikael Köhlmyr | mikael@kohlmyr.com | http://www.kmyr.net
 */
public class Physics {
    //public static int PERMITTED_CONTROL_DISCREPANCY = 5;
    public static int FRAMES_PER_SECOND = 30;
    public static double FRAME_LENGTH = 1000/Physics.FRAMES_PER_SECOND;
    public static int UNIT_OF_LENGTH = 5;
    public static double GRAVITY = Physics.UNIT_OF_LENGTH*3.25/Physics.FRAMES_PER_SECOND;
    public static int MAXIMUM_VELOCITY = 10;

    public static double FRICTION_WALL = 0.3;
    public static double BOUNCE_FLOOR = 1.25;

    /*
     *  OBS. max_vel not in use most places, questionable if useful at all outside of spawning? Won't really be necessary if physics done right
     */
    public static double calc_velocity(double vstart, double acceleration, int time){
        return Math.min((vstart + (acceleration * time)), MAXIMUM_VELOCITY);
    }

    public static double calc_distance(Point2D.Double from, Point2D.Double to){
        return Math.abs(Math.sqrt(((to.x - from.x)*(to.x - from.x)) + ((to.y - from.y)*(to.y - from.y))));
    }

    public static void apply_friction(Point2D.Double velocity, double friction){
        velocity.x *= (1-friction);
        velocity.y *= (1-friction);
    }

    public static void apply_bounce(Point2D.Double velocity, double bounce, double mass){
        velocity.x *= (bounce*(20/mass/Particle.MAX_SIZE));
        velocity.y *= (bounce*(20/mass/Particle.MAX_SIZE));
        // bounces too much for small particles....
    }

    public static double get_velocity_with_gravity(double velocity_toward_center, int time){
        return Physics.calc_velocity(velocity_toward_center, Physics.GRAVITY, time);
    }
}
